var demos=[]
var tbodys=document.querySelector("tbody")
var pageSize =6; //每页显示的记录条数
var page = 1; //当前页，默认第一页
for(var i=0;i<demos.length;i++){
    var newtr=document.createElement("tr")
    newtr.innerHTML= `
         <td>${demos[i].name}</td>
                        <td>${demos[i].address}</td>
                        <td>${demos[i].setdate}</td>
                        <td>${demos[i].enddate}</td>
                        <td>${demos[i].alldate}</td>
                        <td>${demos[i].vehicle}</td>
    `
    tbodys.appendChild(newtr)
}

// 出差
function chucai(){
    var sels=document.querySelector("#sel")
    let seles={
        pageindex:page,
        pagenum:pageSize,
        name:sels.value
    }
    ajaxHttp("post","businesstrip/findBtList",seles).then((res)=>{
        res=JSON.parse(res)
        var data=res.dataset.businesstripList
        console.log(res);
        demos=data
        for(var i=0;i<demos.length;i++){
            var newtr=document.createElement("tr")
            newtr.innerHTML= `
                 <td>${demos[i].userId}</td>
                                <td>${demos[i].businessLocation}</td>
                                <td>${demos[i].createTime}</td>
                                <td>${demos[i].businessDate}</td>
                                <td>${demos[i].businessDuration}</td>
                                <td>${demos[i].businessId}</td>
            `
            tbodys.appendChild(newtr)
            if(sels.value===demos[i].userId){
                tbodys.innerHTML=""
                for(var javascript=0;javascript<demos.length;javascript++){
                    var newtr=document.createElement("tr")
                    newtr.innerHTML= `
                         <td>${demos[j].userId}</td>
                                        <td>${demos[javascript].businessLocation}</td>
                                        <td>${demos[javascript].createTime}</td>
                                        <td>${demos[javascript].businessDate}</td>
                                        <td>${demos[javascript].businessDuration}</td>
                                        <td>${demos[javascript].businessId}</td>
                    `
                    tbodys.appendChild(newtr)
                    }    
            }
        }
    })
}
chucai()



var addopens=document.querySelector(".addopen")

//单击弹出添加出差记录弹窗
function addopen(){
    addopens.style.display="flex"
}

//添加出差
function addchu(){
    var index=localStorage.getItem("userid")
    var num=Number(index)
    var setday=document.querySelector(".setdays")
    var alldays=document.querySelector(".alldays")
    let addchai={
        businessDate:setday.value,
        businessDuration:alldays.value,
        userId:num
    }
    ajaxHttp("post","businesstrip/addBusinesstrip",addchai).then((res)=>{
        // console.log(res);
        alert("添加成功")
        offadd()
        location.reload()
    })
}

function offadd(){
    addopens.style.display="none"
}
